package main

import (
	"fmt"
	"time"
)

var ch chan int

func writer() {
	for i := 0; i < 10; i++ {
		fmt.Println("begin write:", i)
		ch <- i * 2
	}
	close(ch)
}

func main() {
	ch = make(chan int, 5)
	go writer()
	//读取channel
	time.Sleep(time.Second * 5)
	for {
		num, ok := <-ch
		if !ok {
			break
		}
		fmt.Println(num)
		time.Sleep(time.Second * 2)
	}
}
